package com.service;

import com.dao.userdao.Register;
import com.pojo.User;
import com.util.EmailUtil;
import com.util.MD5Util;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class RegisterService {

      public static void register(HttpServletRequest req) throws IOException {
              String mailbox=req.getParameter("mailbox");
              String str = mailbox.substring(0, mailbox.indexOf("@"));
              //用户id由qq号+下划线+四位随机数组成
              String username=str+"_"+ EmailUtil.creatCode(4);
              /*对密码进行加密*/
              MD5Util md=new MD5Util();
              String password= md.digest(req.getParameter("password"));
              User user=new User();
              user.setNickname(req.getParameter("nickname"));
              user.setGender("male");
              user.setBorndate("2003-08-15");
              user.setPassword(password);
              user.setMailbox(req.getParameter("mailbox"));
              user.setUsername(username);
              user.setHeadpicture("../warehouse/默认头像.png");
              user.setRegion("未知星球");
              user.setIntro("这个用户啥也没说");
              Register.user_register(user);
      }
}
